<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <div class="report-container"></div>
    </el-card>
  </div>
</template>

<script>
import ECharts from 'echarts'
import _ from 'lodash'
export default {
  data() {
    return {
      options: {
        title: {
          text: '数据报表'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  created() {
  },
  methods: {
  },
  async mounted() {
    const { data: res } = await this.$http.get('reports/type/1')
    if(res.meta.status !== 200) return this.$message({ type: 'error', message: res.meta.msg, duration: 2000 })
    const myChart = ECharts.init(document.querySelector('.report-container'))
    const option = _.merge(res.data, this.options)
    myChart.setOption(option)
  }
}
</script>

<style lang="less" scoped>
  .report-container{
    height: 400px;
    width: 800px;
  }
</style>
